﻿
using Web.UI;
using MAF.UserSecurity;
using System.Web;
using System;
using System.Collections.Generic;
using MAF.Common;

namespace Web.Controller
{
    public class UserHandler
    {
        public void LogonUser()
        {
            SecurityUI.LogonUser();
        }

        public void Add()
        {
            User info = MAF.Common.ObjectConverter.ToObject<User>(HttpContext.Current.Request.Form);
            Manager.AddUser(info);
        }

            public void Update()
            {
                User info = MAF.Common.ObjectConverter.ToObject<User>(HttpContext.Current.Request.Form);
                Manager.UpdateUser(info);
            }

            public int Delete()
            {
                Guid id = new Guid(HttpContext.Current.Request.Form["Id"]);
                return Manager.RemoveUser(id);
            }

            public User Show()
            {
                string id = HttpContext.Current.Request.QueryString["Id"];
                return Manager.GetUser(new Guid(id));
            }

            public List<User> Index()
            {
                PageInfo p;
                return Index(out p);
            }

            public List<User> Index(out PageInfo page)
            {
                Query<User> q = new Query<User>();
                q.AddCriterionsByQueryString(HttpContext.Current.Request.QueryString.ToString());
                List<User> list = Manager.GetUserList(q);

                page = new PageInfo(10,1);         // 返回page
                return list;            // 返回list
            }

            /// <summary>
            /// 提供使用固定ParentId的方法
            /// </summary>
            /// <param name="parentId"></param>
            /// <returns></returns>
            //public List<User> Index(Guid parentId)
            //{
            //    BaseQueryVo vo = new BaseQueryVo();
            //    vo.ParentId = parentId.ToString();
            //    return GetService().Index(vo);
            //}
    }
}
